﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using WP.Modules;
using WP.DB;
using WP.Controls;
using WP.Commons;
using System.Collections;
namespace WP.IM.Form
{
    public partial class frmCopyItem : BaseQryRpt 
    {
        private DBAccess mdbcon = new DBAccess(false, false);
        private bool mblnPressExit = true;
        public frmCopyItem()
        {
            InitializeComponent();
        }


        public bool ShowCopyItem(ref string strNewItemNo,ref string strNewSupName)
        {
            this.Text = "复制到新物料";
            this.ShowDialog();
            if (!mblnPressExit)
            {
                strNewItemNo = txtItemNo.Text;
                strNewSupName = txtSupName.Text;
                return true;
            }
            return false;
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            string strErrMsg = "";
            if (VaildCheck(ref strErrMsg ))
            {
                mblnPressExit = false;
                this.Close();
            }
            else
            {
                if (strErrMsg != "")
                {
                    MessageBox.Show(strErrMsg, SysVar.WarnTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }

        private bool VaildCheck(ref string strErrMsg )
        {
            if (txtItemNo.Text.Trim() == "")
            {
                strErrMsg = "物料代码不能为空。";
                return false;
            }
            string strSQL = "select * from iminvmaster where  itemno='{0}' and supname='{1}'";
            strSQL = string.Format(strSQL, txtItemNo.Text, txtSupName.Text);
            DataRow drCheck = mdbcon.GetDataFirstRow(strSQL);
            if (drCheck != null)
            {
                strErrMsg = "物料已经存在。请检查。";
                return false;
            }
            return true;
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            mblnPressExit = true;
            this.Close();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {

        }
    }
}
